home *** CD-ROM | disk | FTP | other *** search
- #include <AppleEvents.h>
- #include "AppEventDefs.h"
- #include "AppEvents.h"
- #include "MyHandlers.h"
- #include "TestBed.h"
- #include "Gripe.h"
-
- static StringPtr gServiceName;
-
- OSErr InitReqHandlers( void )
- {
- OSErr err;
-
- if ( err = AEInstallEventHandler( kCoreEventClass,
- kAEOpenApplication,
- (EventHandlerProcPtr)MyOAPPHandler,
- 0,
- false ) ){
- Gripe( "\poapp install failed" );
- return err;
- }
-
- if ( err = AEInstallEventHandler( kCoreEventClass,
- kAEOpenDocuments,
- (EventHandlerProcPtr)MyODocHandler,
- 0,
- false ) ){
- Gripe( "\podoc install failed" );
- return err;
- }
-
- if ( err = AEInstallEventHandler( kCoreEventClass,
- kAEPrintDocuments,
- (EventHandlerProcPtr)MyPDocHandler,
- 0,
- false ) ){
- Gripe( "\ppdoc install failed" );
- return err;
- }
-
- if ( err = AEInstallEventHandler( kCoreEventClass,
- kAEQuitApplication,
- (EventHandlerProcPtr)MyQuitHandler,
- 0,
- false ) ){
- Gripe( "\pquit install failed" );
- return err;
- }
-
- if ( err = AEInstallEventHandler( kCoreEventClass,
- kAEAnswer,
- (EventHandlerProcPtr)MyAnswerHandler,
- 0,
- false ) ){
- Gripe( "\pAnswer install failed" );
- return err;
- }
-
- return noErr;
- }
-
- /* This gets a connection using the PPC browser. From IM VI p. 6-58 */
-
- OSErr GetTargetAddress( StringPtr myPrompt,
- StringPtr myAppStr,
- PortInfoRec *myPortInfoPtr,
- AEAddressDesc *targetAddressPtr,
- StringPtr serviceName,
- TargetID *toTargetIDPtr )
- {
- OSErr err;
-
- gServiceName = serviceName;
-
- err = PPCBrowser( myPrompt,
- myAppStr,
- false,
- &( toTargetIDPtr->location ),
- myPortInfoPtr,
- (PPCFilterProcPtr)MyPPCBrowseProc,
- (StringPtr)"\p" );
- if ( err )
- return err;
-
- BlockMove( &(myPortInfoPtr->name),
- &(toTargetIDPtr->name),
- sizeof(myPortInfoPtr->name) );
-
- err = AECreateDesc( typeTargetID,
- (Ptr)toTargetIDPtr,
- sizeof( *toTargetIDPtr ),
- targetAddressPtr );
-
- return err;
- }
-
- pascal Boolean MyPPCBrowseProc( LocationNamePtr theLoc, PortInfoPtr thePortInfo )
- {
- return true;
- #ifdef NEVER
- if ( thePortInfo->name.portKindSelector == ppcByString ){
- if ( PStrCmp( thePortInfo->name.u.portTypeStr, (StringPtr)"\pWORDSERVICES" ) )
- return true;
- else
- return false;
- }
- return false;
- #endif
- }
-
- Boolean PStrCmp( StringPtr foo, StringPtr bar )
- {
- short len;
-
- len = (short)( foo[ 0 ] );
-
- len += 1; /* include the length byte itself */
-
- while ( len-- )
- if ( *foo++ != *bar++ )
- return false;
-
- return true;
- }
-
- /* GetEventType is a utility routine to get the event class and ID out of an apple event */
-
- OSErr GetEventType( AppleEvent *theAppleEventPtr,
- AEEventClass *theClassPtr,
- AEEventID *theIDPtr )
- {
- OSErr err;
- Size realSize;
- DescType realType;
-
- /* Get the event class */
-
- err = AEGetAttributePtr( theAppleEventPtr,
- keyEventClassAttr,
- typeType,
- &realType,
- (Ptr)theClassPtr,
- (Size)sizeof( AEEventClass ),
- &realSize );
-
- if ( err )
- return err;
-
- /* Get the event ID */
-
- err = AEGetAttributePtr( theAppleEventPtr,
- keyEventIDAttr,
- typeType,
- &realType,
- (Ptr)theIDPtr,
- (Size)sizeof( AEEventID ),
- &realSize );
-
-
- return err;
- }
-
- OSErr GetEventID( AppleEvent *theAppleEventPtr,
- AEEventID *theIDPtr )
- {
- OSErr err;
- Size realSize;
- DescType realType;
-
- /* Get the event ID */
-
- err = AEGetAttributePtr( theAppleEventPtr,
- keyEventIDAttr,
- typeType,
- &realType,
- (Ptr)theIDPtr,
- (Size)sizeof( AEEventID ),
- &realSize );
-
-
- return err;
- }
-